{{Operating System Research Build Receiver}}  

CON
  _clkmode = xtal1 + pll16x                                               
  _xinfreq = 5_000_000

OBJ
  xbee      : "XBee_Object.spin"
  pst       : "Parallax Serial Terminal"
  functions : "Functions.spin"
  
VAR
  long stack[10] 
  byte drive

  byte Forward
  byte Reverse
  byte Left
  byte Right
  byte Stop
  
PUB Main  
  pst.start(115200)
  waitcnt(clkfreq + cnt)
  functions.initialize
  pst.str(String("Starting to receive packets from transmitter.",13))
  xbee.start(4,3,0,9600)
  
  pst.str(String("Received the following: ",13))
  drive := cognew(functions.Drive(Stop), @stack) 
  repeat
    Parse
    
PRI Parse  
  pst.dec(xbee.rx)
  pst.str(String(13))
  CASE xbee.rx
    1: cogstop(drive)
       coginit(drive, functions.Drive(Stop), @stack)
    2: cogstop(drive)
       coginit(drive, functions.Drive(Reverse), @stack)
    3: cogstop(drive)
       coginit(drive, functions.Drive(Forward), @stack)
    4,5:
      if (xbee.rx == 4)
        cogstop(drive)
        coginit(drive, functions.Drive(Right), @stack)
      if (xbee.rx ==5)
        cogstop(drive)
        coginit(drive, functions.Drive(Left), @stack)
    OTHER: pst.str(String("What is this?",13))
